structure Parse : sig val parse : string -> unit 
		      val main : string * string list -> OS.Process.status end =
struct 
  structure TigerLrVals = TigerLrValsFun(structure Token = LrParser.Token);

  structure TigerLex = TigerLexFun(structure Tokens = TigerLrVals.Tokens);

  structure TigerParser = Join(structure ParserData = TigerLrVals.ParserData
                               structure Lex = TigerLex
			       structure LrParser = LrParser);

  fun parse filename =
      let val _ = (ErrorMsg.reset(); ErrorMsg.fileName := filename)
	  val file = TextIO.openIn filename
	  fun get _ = TextIO.input file
	  fun parseError(s,p1,p2) = ErrorMsg.error p1 s
	  val lexer = LrParser.Stream.streamify (TigerLex.makeLexer get)
	  val (absyn, _) = TigerParser.parse(30,lexer,parseError,())
      in TextIO.closeIn file;
	 absyn
      end handle LrParser.ParseError => raise ErrorMsg.Error;

  fun main(_, fs) = let fun loop [] = OS.Process.success
			  | loop [f] = ( parse f
				       ; OS.Process.success
				       )
			  | loop (f::fs) = ( parse f
					   ; print "\n"
					   ; loop fs
					   )
		    in loop fs
		    end;

end
